//
//  UIImage+DisclosureIndicator.m
//  LDSSmartHome
//
//  Created by kai_leedarson on 2017/11/8.
//  Copyright © 2017年 leedarson. All rights reserved.
//

#import "UIImage+DisclosureIndicator.h"

@implementation UIImage (DisclosureIndicator)

+ (UIImage *)DisclosureIndicatorImage {
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"IndicatorImage"];
    if (data) {
        return  [UIImage imageWithData:data];
    } else {
        UIImage *resultImage = [UIImage imageWithSize:CGSizeMake(7.5, 12.5) tintColor:[UIColor colorWithRed:199/255.0 green:199/255.0 blue:207/255.0 alpha:0.9]];
        NSData *data = UIImagePNGRepresentation(resultImage);
        [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"IndicatorImage"];
        return resultImage;
    }

}

+ (UIImage *)imageWithSize:(CGSize)size tintColor:(UIColor *)tintColor {
    UIImage *resultImage = nil;
    tintColor = tintColor ? tintColor : [UIColor whiteColor];
    UIGraphicsBeginImageContextWithOptions(size, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    UIBezierPath *path = nil;
    path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0,0)];
    [path addLineToPoint:CGPointMake(size.width-1, size.height/2)];
    [path addLineToPoint:CGPointMake(0,size.height)];
    CGContextSetStrokeColorWithColor(context, tintColor.CGColor);
    path.lineWidth = 2.0f;
    [path stroke];
    resultImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return resultImage;
}

@end
